package neves.android.etmg.tilemap.mapcreater;

import neves.android.etmg.tilemap.TileMap;

public class TileMapCreater_MultiRoom extends TileMapCreater {

	/*
	 * (non-Javadoc)
	 * 
	 * @see neves.android.etmg.MapCreater#CreateMap(neves.android.etmg.TileMap)
	 */
	public TileMap CreateMap() {
		
		int mapWidth = 128;
		int mapHeight = 128;
		int roomSizeFactor = 32;  // max width or height for each room
		int miniumRooms = 5;
		int maxiumRooms = 12;//Math.min((int)mapWidth/roomSizeFactor,(int)mapHeight/roomSizeFactor);
		
		
		targetMap = new TileMap(mapWidth, mapHeight);
		
		int realRoomCount = 0;
		
		int makeRoomRounds= RandomNumber(miniumRooms, maxiumRooms);
		
		// {roomX,roomY,roomWidth,roomHeight,isConnected}
		int[][] roomData = new int[makeRoomRounds][5];
		
		while (realRoomCount<miniumRooms){
			for(int temRoundI = 0 ; temRoundI<makeRoomRounds; temRoundI++ ){
				int ranPx = RandomNumber(0,mapWidth-roomSizeFactor);
				int ranPy = RandomNumber(0,mapHeight-roomSizeFactor);
				int[] room_size = RandomARoomSize(4, roomSizeFactor);
				
				boolean isRoomReal = (targetMap.MakeARoom(ranPx, ranPy,room_size[0], room_size[1]));
				
				if(isRoomReal){
					
					roomData[realRoomCount] = new int[]{ranPx,ranPy,room_size[0],room_size[1],0};
					
					realRoomCount++;
					
					// connect this room to previous room
					if(realRoomCount>1){
						//ConnectTwoRoom(roomData[realRoomCount-1],roomData[realRoomCount]);
					}
				}

				
				if(realRoomCount==makeRoomRounds){
					break;
				}
				
			}
			
			
		}
		
		for(int temi = 0 ; temi<realRoomCount-1;temi++){
			ConnectTwoRoom(roomData[temi],roomData[temi+1]);
		}
		
		
		return targetMap;
		
		
	}
	
	

}
